package com.market.service.impl;

import com.market.constants.DiscountConst;
import com.market.constants.MoneyOffConst;
import com.market.constants.PriceConst;
import com.market.model.Fruit;
import com.market.model.Market;
import com.market.service.IMarketService;

import java.math.BigDecimal;

/**
 * @description: **
 * @projectName: Market
 * @package: com.market.service.impl
 * @className: MarketImpl
 * @author: JasonVae
 * @date: 2023-03-17 11:11
 */
public class MarketImpl implements IMarketService {
    @Override
    public BigDecimal calcPriceA(int appleQuantity, int strawberryQuantity) {
        Market market = new Market();
        market.addFruit(new Fruit("苹果", PriceConst.APPLE_PRICE, appleQuantity));
        market.addFruit(new Fruit("草莓", PriceConst.STRAWBERRY_PRICE, strawberryQuantity));
        return market.getTotalPrice();
    }

    @Override
    public BigDecimal calcPriceB(int appleQuantity, int strawberryQuantity, int mangoQuantity) {
        Market market = new Market();
        market.addFruit(new Fruit("苹果", PriceConst.APPLE_PRICE, appleQuantity));
        market.addFruit(new Fruit("草莓", PriceConst.STRAWBERRY_PRICE, strawberryQuantity));
        market.addFruit(new Fruit("芒果", PriceConst.MANGO_PRICE, mangoQuantity));
        return market.getTotalPrice();
    }

    @Override
    public BigDecimal calcPriceC(int appleQuantity, int strawberryQuantity, int mangoQuantity) {
        Market market = new Market();
        market.addFruit(new Fruit("苹果", PriceConst.APPLE_PRICE, appleQuantity));
        market.addFruit(new Fruit("草莓", PriceConst.STRAWBERRY_PRICE, strawberryQuantity, DiscountConst.STRAWBERRY_DISCOUNT));
        market.addFruit(new Fruit("芒果", PriceConst.MANGO_PRICE, mangoQuantity));
        return market.getTotalPrice();
    }

    @Override
    public BigDecimal calcPriceD(int appleQuantity, int strawberryQuantity, int mangoQuantity) {
        Market market = new Market();
        market.addFruit(new Fruit("苹果", PriceConst.APPLE_PRICE, appleQuantity));
        market.addFruit(new Fruit("草莓", PriceConst.STRAWBERRY_PRICE, strawberryQuantity, DiscountConst.STRAWBERRY_DISCOUNT));
        market.addFruit(new Fruit("芒果", PriceConst.MANGO_PRICE, mangoQuantity));
        BigDecimal totalPrice = market.getTotalPrice();
        //判断总价是否小于100
        if (totalPrice.compareTo(MoneyOffConst.MONEY_FULL) < 0) {
            return totalPrice;
        }
        //满100-10（优惠不叠加）
        return totalPrice.subtract(MoneyOffConst.MONEY_SUBTRACTION);
    }
}
